<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>


<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>

<bean:define id="micrositeNaviInfoParams" name="micrositeNaviInfoView" property="urlParams" scope="request" />

<script language="JavaScript">

function confirmCancel(theForm) {
  if ( confirm('<bean:message key="cs.folder.cancel.edit.confirm"/>') ){
    theForm.action = '<html:rewrite page="/cs/documentIndex.do" />';
    theForm.submit();
  } else {
    return false;
  }
}        

//
// Trims leading blanks.
//
function stringLeftTrim(s)
{
  return s.replace(/^ +/, "");
}

//
// Trims trailing blanks.
//
function stringRightTrim(s)
{
  return s.replace(/ +$/, "");
}

//
// Trims leading and trailing blanks.
//
function stringTrim(s)
{
  return stringRightTrim(stringLeftTrim(s));
}

function validateForm(theForm) {
  if ( theForm.name != null &&  stringTrim(theForm.name.value) == '' ) {
    theForm.name.value = "";
    alert('<bean:message key="cs.folder.name.not.empty"/>');
    return;
  }
  theForm.name.value = stringTrim(theForm.name.value);

  var folderDesc = stringTrim(theForm.description.value);
  if (folderDesc.length > 2000) {
    alert('<bean:message key="cs.folder.description.length.limit"/>');
    return;
  }
 
  if (theForm.selectedOwnerIds.value == null || theForm.selectedOwnerIds.value == "") {
    alert('<bean:message key="cs.folder.owner.more"/>');
    return;
  }

  theForm.submit();
}

//
// Create a dummy (timestamp) attribute to get around an IE cache problem.
//
function getTimeStamp() {
   var now = new Date;
   var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
   return timestamp;
}   


function selectOwnerPopup(theForm) {

  var popupURL = '<html:rewrite page="/cs/folderSelectOwner.do" name="micrositeNaviInfoParams" />';
  var timestamp = getTimeStamp();
  popupURL += '&timestamp=' + timestamp;

  var win = window.open('', "FolderSelectOwner", "width=500,height=400,scrollbars=yes,resizable=yes");
  if ( win != null) {
    if( win.opener == null) {
      win.opener = self;
    }
  }
  win.focus();
  // save the current form setting so that it can be restored later
  var oldAction = theForm.action;
  var oldTarget = theForm.target;
  // submit the form to the popup so that we can pass the groupIds to the popup
  theForm.action = popupURL;
  theForm.target = "FolderSelectOwner";   
  theForm.submit();
  theForm.action = oldAction;
  theForm.target = oldTarget;
}

function setOwner(selectedOwnerIdName) {
  var ownerIds = new Array;
  var ownerNames = new Array;
  for (var idx = 0; idx < selectedOwnerIdName.length; ++idx) {
    var idName = selectedOwnerIdName[idx].split("##");
    var selectedOwnerId = idName[0];
    var selectedOwnerName = idName[1];
    ownerIds[idx] = selectedOwnerId;
    ownerNames[idx] = selectedOwnerName;
  }
  document.csFolderEditForm.selectedOwnerIds.value = ownerIds.join(",");
  document.csFolderEditForm.selectedOwnerNames.value = ownerNames.join(", ");
}

</script>
<!-- BEGIN form ( csFolderEditForm ) -->

<html:form action="/cs/folderSave.do">
<bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>

<!-- Zone 5 starts here.  -->
      
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="content area">
  <tr>
    <td valign="top">
    
    <!--start microsite logo and name here-->
      <div class="pageTitle">
        <%@ include file="/cs/microsite/micrositeNaviInfo.jsp" %>
      </div> 
    <!--end microsite logo and name here-->
    
    <!--start title bar here-->
    <div class="pageSubtitle">
      <span class="left">
        <bean:write name="folderEditView" property="pageTitle"/>
      </span>
    </div>  
    
    <div class="blockWrap">
    
    <!-- start Page Instructions -->
    <div class="pageInstructions">
      <bean:message key="cs.folder.edit.notes" />
    </div>
    <!-- End Page Instructions -->
    
    <!-- Display folder info -->
    <table class="labelForm" width="100%" border="0" cellspacing="0" 
           cellpadding="0" summary="Folder Information">
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.folder.name"/>*: </td>
        <td width="80%" class="labelField"> 
          <html:text property="name" size="30" maxlength="80"/>
        </td>
      </tr>
      <tr>
        <td nowrap width="20%" class="label"><bean:message key="cs.folder.description"/>:</td>
        <td width="80%" class="labelField"><html:textarea property="description" rows="5" cols="31"/></td>
      </tr>
      <logic:equal name="micrositeNaviInfoView" property="micrositeTemplatePhaseFlag" value="true">
        <tr>
          <td nowrap width="20%" class="label"><bean:message key="cs.phase"/>:</td>
          <td width="80%" class="labelField">
            <bean:write name="folderEditView" property="phaseName" />
          </td>
        </tr>
      </logic:equal>
    
      <tr>
        <td nowrap width="20%" class="label"><bean:message key="cs.folder.editor.groups"/>:</td>
        <td width="80%" class="labelField">
          <html:select property="editorGroupIds" size="4" multiple="true">
            <html:optionsCollection name="folderEditView" property="editorGroupCandidates" />
          </html:select>
        </td>
      </tr>

      <tr>
        <td nowrap width="20%" class="label"><bean:message key="cs.folder.author.groups"/>:</td>
        <td width="80%" class="labelField">
          <html:select property="authorGroupIds" size="4" multiple="true">
            <html:optionsCollection name="folderEditView" property="authorGroupCandidates" />
          </html:select>
        </td>
      </tr>
  
      <tr>
        <td nowrap width="20%" class="label"><bean:message key="cs.folder.reader.groups"/>:</td>
        <td width="80%" class="labelField">
          <html:select property="readerGroupIds" size="4" multiple="true">       
            <html:optionsCollection name="folderEditView" property="readerGroupCandidates" />
          </html:select>
        </td>
      </tr>

      <tr>
        <td nowrap width="20%" class="label"><bean:message key="cs.owners"/>*:</td>
        <td width="80%" class="labelField">
          <input type="hidden" name="selectedOwnerIds" value="<bean:write name="csFolderEditForm" property="selectedOwnerIds"/>" >
          <textarea name="selectedOwnerNames" cols=31 rows=4 wrap=virtual readonly><bean:write name="csFolderEditForm" property="selectedOwnerNames"/></textarea>
          <html:button property="selectOwner" onclick="selectOwnerPopup(this.form)" styleClass="inputButton">
            <bean:message key="cs.button.select.owner"/>
          </html:button>
        </td>
      </tr>
    </table>
    
    <!--start cancel, reset, save bar area here-->

    <div class="pageButtonWrap" align="right">
      <html:reset styleClass="pageButton" property="resetBtn" titleKey="button.reset">
        <bean:message key="button.reset"/>
      </html:reset>
                   
	&nbsp;&nbsp;
      <html:button styleClass="pageButton" property="cancelBtn" 
             titleKey="button.cancel" onclick="confirmCancel(this.form)">
        <bean:message key="button.cancel"/>
      </html:button>

      <html:button styleClass="pageButton" property="saveBtn"
             titleKey="button.save" onclick="validateForm(this.form)" >
        <bean:message key="button.save"/>
      </html:button>

    </div>
    <!--end cancel, reset, save bar area here-->
    
    </div>
    </td>
  </tr>
</table>
</html:form>

<!-- END form ( csFolderEditForm ) -->

